﻿using MediatR;
using Microsoft.AspNetCore.Http;
using Microsoft.AspNetCore.Mvc;
using U.B.ErrorCode;
using U.B.WriteApi.Command;

namespace U.B.WriteApi.Controllers
{
    [Route("api/[controller]/[action]")]
    [ApiController]
    public class LevaController : ControllerBase
    {
        public readonly IMediator _mediator;
         public LevaController(IMediator mediator)
        {
            _mediator = mediator;
        }
        // <summary>
        /// 添加申请
        /// </summary>
        /// <param name="request">命令</param>
        /// <returns>APIResult</returns>
        [HttpPost]
        public async Task<ApiResult<int>> AddLeave(AddLevaCommand request)
        {
            return await _mediator.Send(request);

        }
        /// <summary>
        /// 删除申请
        /// </summary>
        /// <param name="request"></param>
        /// <returns></returns>
        [HttpDelete]
        public async Task<ApiResult<string>> DelLeave([FromQuery] DelLevaCommand request)
        {
            return await _mediator.Send(request);
        }
        /// <summary>
        /// 审批
        /// </summary>
        /// <param name="request">命令</param>
        /// <returns>APIResult</returns>
        [HttpPost]
        public async Task<ApiResult<string>> UpdateLeave(UpdateLeaveCommand request)
        {
            return await _mediator.Send(request);
        }
        /// <summary>
        /// 修改申请
        /// </summary>
        /// <param name="request">命令</param>
        /// <returns>APIResult</returns>
        [HttpPost]
        public async Task<ApiResult<string>> UpdLeave(UpdLeaveCommand request)
        {
            return await _mediator.Send(request);
        }

    }
}
